package com.cyw.wearth.api;

import com.cyw.wearth.test.Grades;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.xml.crypto.Data;

/**
 * @author : cyw
 * @date : created in  下午7:56 2021/6/11
 * @description :  天气API
 * @modified by :
 * @Version : $
 */
@Service
public class WeatherApi {
    @Autowired
    private RestTemplate restTemplate;
    private static String URL = "https://public-weather-json.s3.ap-east-1.amazonaws.com/weather.json";
    public void  getWeatherData(){
        ResponseEntity resultResponseEntity = restTemplate.getForEntity(URL,Object.class);
        System.out.println(resultResponseEntity.getBody());
    }
    public Object  getWeatherDataUrl(){
        ResponseEntity resultResponseEntity = restTemplate.getForEntity(URL,Object.class);
        return resultResponseEntity.getBody();
    }
    public void  testJson() throws JsonProcessingException {
        String jsonStr = "{\"name\":\"三班\",\"students\":[{\"age\":25,\"gender\":\"female\",\"grades\":\"三班\",\"name\":\"露西\",\"score\":{\"网络协议\":98,\"JavaEE\":92,\"计算机基础\":93},\"weight\":51.3},{\"age\":26,\"gender\":\"male\",\"grades\":\"三班\",\"name\":\"杰克\",\"score\":{\"网络安全\":75,\"Linux操作系统\":81,\"计算机基础\":92},\"weight\":66.5},{\"age\":25,\"gender\":\"female\",\"grades\":\"三班\",\"name\":\"莉莉\",\"score\":{\"网络安全\":95,\"Linux操作系统\":98,\"SQL数据库\":88,\"数据结构\":89},\"weight\":55}]}";
        ObjectMapper mapper = new ObjectMapper();
        Grades grades = mapper.readValue(jsonStr,Grades.class);
        System.out.println(grades.toString());
    }
}
